package com.team2.insulatingtools.modular.tools.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.team2.insulatingtools.modular.tools.entity.Scrap;
import com.team2.insulatingtools.modular.tools.pojo.request.ScrapRequest;
import com.team2.insulatingtools.modular.tools.pojo.response.ScrapHistoryResponse;
import com.team2.insulatingtools.modular.tools.service.ScrapService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 绝缘工具 控制器
 *
 * @author team2
 * @date 2023/04/03 09:48
 */
@RestController
@ApiResource(name = "报废信息")
public class ScrapController {


    @Resource
    private ScrapService scrapService;

    @PostResource(name = "添加", path = "/scrap/add")
    public ResponseData<?> add(@RequestBody @Validated(ScrapRequest.add.class) ScrapRequest scrapRequest) {
        int add = scrapService.add(scrapRequest);
        return new SuccessResponseData<>(add);
    }

    @GetResource(name = "获取报废列表", path = "/scrap/list")
    public ResponseData<List<Scrap>> list(ScrapRequest scrapRequest) {
        return new SuccessResponseData<>(scrapService.findList(scrapRequest));
    }

    @GetResource(name = "获取未补充报废列表", path = "/scrap/listwithoutsup")
    public ResponseData<List<Scrap>> listwithoutsup(ScrapRequest scrapRequest) {
        return new SuccessResponseData<>(scrapService.findListWithSup(scrapRequest));
    }


    @GetResource(name = "查询试验记录", path = "/scrap/historylist")
    public ResponseData<List<ScrapHistoryResponse>> historylist(ScrapRequest scrapRequest) {

        return new SuccessResponseData<>(scrapService.findHistoryList(scrapRequest));
    }

    @GetResource(name = "获取所有报废信息", path = "/scrap/selectall")
    public ResponseData<List<Scrap>> selectall() {
        return new SuccessResponseData<>(scrapService.all());
    }

    @GetResource(name = "根据车间名称获取报废列表", path = "/scrap/querybuworkshop")
    public ResponseData<List<Scrap>> querybuworkshop(ScrapRequest scrapRequest) {
        return new SuccessResponseData<>(scrapService.queryByWorkShop(scrapRequest.getWorkshop()));
    }
}
